//
//  MSBillCell.m
//  SocietySale
//
//  Created by Mike on 16/11/18.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSBillCell.h"

@interface MSBillCell ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subLabel;
@property (nonatomic, strong) UILabel *coinLabel;
@end

@implementation MSBillCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    self.titleLabel = [self creatLabel:CGRectMake(12, 13, SCREEN_WIDTH-50, 20)];
    self.subLabel = [self creatLabel:CGRectMake(12, self.titleLabel.bottom+5, SCREEN_WIDTH-50, 20)];
    self.coinLabel = [self creatLabel:CGRectMake(SCREEN_WIDTH-212, 0, 200, 70)];
    self.coinLabel.textAlignment = NSTextAlignmentRight;
    
    _horizonLineView =[[UIView alloc] initWithFrame:CGRectMake(12, 69.4, SCREEN_WIDTH-24, 0.6)];
    _horizonLineView.backgroundColor = kNormalGray;
    [self.contentView addSubview:_horizonLineView];
}

//创建label
- (UILabel*)creatLabel:(CGRect)frame{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.font = HeitiFont(15);
    label.textColor = kLightBlackColor;
    [self addSubview:label];
    return label;
}

- (void)setModel:(MSCommonModel *)model{
    _model = model;
    self.titleLabel.text = model.title;
    
    NSMutableAttributedString *timeAttstr = [[NSMutableAttributedString alloc] initWithString:model.subTitle attributes:@{NSFontAttributeName:HeitiFont(13),NSForegroundColorAttributeName:kDarkGrayColor}];
    
    NSTextAttachment *textAttachment2 = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    textAttachment2.bounds = CGRectMake(0, -2.5, 14, 14);
    textAttachment2.image = [UIImage imageNamed:@"time"];
    NSAttributedString *attachmentString2 = [NSAttributedString attributedStringWithAttachment:textAttachment2];
    [timeAttstr insertAttributedString:attachmentString2 atIndex:0];
    self.subLabel.attributedText = timeAttstr;
    
    NSString *unit = @"";
//    if ([model.type isEqualToString:@"newRegister"] || [model.type isEqualToString:@"transmit"] ||[model.type isEqualToString:@"invite"] ||[model.type isEqualToString:@"dealSuccess"]) {
//        unit = @"+";
//    }
//    else if ([model.type isEqualToString:@"publishBuy"] || [model.type isEqualToString:@"exchangeLeaguer"]){
//        unit = @"-";
//    }
    NSString *price = [NSString stringWithFormat:@"%@%@",unit,model.thirdTitle];
    NSMutableAttributedString *priceAttstr = [[NSMutableAttributedString alloc] initWithString:price attributes:@{NSFontAttributeName:HeitiFont(22),NSForegroundColorAttributeName:[UIColor blackColor]}];
    
    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    textAttachment.bounds = CGRectMake(0, 0, 17, 17);
    textAttachment.image = [UIImage imageNamed:@"coin"];
    NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
    [priceAttstr insertAttributedString:attachmentString atIndex:0];
    
    self.coinLabel.attributedText = priceAttstr;
}

@end
